	package controllers;

	import play.*;
	import play.mvc.*;

	import views.html.*;

	import play.data.*;
	import static play.data.Form.*;
import models.*;

public class CategorieCont extends Controller {

		static Form<Categorie> categorieForm = form(Categorie.class);

		public static Result index() {
			return redirect(routes.CategorieCont.categories());
		}

		public static Result categories() {
			return ok(categorie.render(Categorie.all(), categorieForm, Utilisateur.find.where().eq("pseudo_utilisateur", session("pseudo_utilisateur")).findUnique()));
		}

		public static Result newCategorie() {
			Form<Categorie> filledForm = form(Categorie.class).bindFromRequest();
			if(filledForm.hasErrors())
			{
				//return badRequest(views.html.index.render(Categorie.all(), filledForm));
				return ok("Hello world");
			}
			else
			{
				Categorie.create(filledForm.get());
				return redirect(routes.CategorieCont.categories());
			}
		}

		public static Result deleteCategorie(Integer id) {
			Categorie.delete(id);
			return redirect(routes.CategorieCont.categories());
			
		}
}
